package models

import "gorm.io/gorm"

type Novel struct {
	gorm.Model
	Title   string `gorm:"type:varchar(200);unique;not null" json:"title"`
	Author  string `gorm:"type:varchar(30);not null" json:"author"`
	Content string `gorm:"type:longtext" json:"content"`
	Status  int    `gorm:"type:tinyint(1);not null;default:0" json:"status"`
}

// 添加小说add
func (n *Novel) Add() error {
	return DB.Create(&n).Error
}

// 获取小说列表list
func (n *Novel) List() (novels []*Novel, err error) {
	err = DB.Debug().Where("status = 1").Find(&novels).Error
	return novels, err
}

// 删除小说del
func (n *Novel) Del() error {
	return DB.Delete(&n).Error
}

// 修改小说update
func (n *Novel) Update() error {
	return DB.Updates(&n).Error
}

// 获取小说详情detail
func (n *Novel) Detail() error {
	return DB.First(&n).Error
}
